import random

class a:
    """
        注：这里有一个小bug，第一个元素无法参加正常的排序，需要在列表中添加一个废元素
        有序链表
        插入函数：insert (递增一个顺序)
        打印函数：printf
        查找函数：find (返回下标)
        删除函数：delete (删除第一个出现的元素)
    """
    def __init__(self):
        self.next = None
        self.size = 0

    def insert(self, value):
        self.size += 1
        head = self.next
        if head is None:
            temp = Node(value)
            self.next = temp
            return
        while head.next is not None:
            if head.next.value >= value:
                temp = Node(value)
                temp.next = head.next
                head.next = temp
                return
            head = head.next
        temp = Node(value)
        head.next = temp
        return

    def printf(self):
        head = self.next
        while head:
            print(head.value, end=' ')
            head = head.next

    def find(self, value):
        head = self.next
        i = 0
        while head:
            i += 1
            if head.value == value:
                return i
            head = head.next
        return -1

    def delete(self, value):
        head = self.next
        while head.next:
            if head.next.value == value:
                head.next = head.next.next
                self.size -= 1
                return 1
            head = head.next
        return -1

class Node:
    def __init__(self, value):
        self.value = value
        self.next = None

    def getNext(self):
        return self.next


if __name__ == '__main__':
    a = a()
    text = [0, 28, 74, 81, 38, 80, 100, 57, 6, 71, 85, 66, 45, 40, 72, 5]
    # for i in range(15):
    #     text.append(random.randint(0, 100))
    for i in text:
        a.insert(i)
    print(text)
    a.printf()
    print()
    print(a.delete(6))
    a.printf()
    print()
    print(a.find(85))
